package exam.beike.S1;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static int n;
    public static String s;
    public static int[] cnt;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        sc.nextLine();
        s = sc.nextLine();
        initCnt();
        System.out.println(dfs(0));
    }

    public static int getIndex(int left, int right) {
        int front = (n + n - left + 1) * left / 2;
        return right - left + front;
    }

    public static void initCnt() {
        cnt = new int[(n+1)*n/2];
        int[] times = new int[26];
        for (int left=0; left<n; ++left) {
            Arrays.fill(times, 0);
            for (int right=left; right<n; ++right) {
                int idx = getIndex(left, right);
                int i = s.charAt(right)-'a';
                if (left == right)
                    cnt[idx] = -1;
                else {
                    if (times[i] == 0)
                        cnt[idx] = cnt[idx-1] - 1;
                    else if (times[i] % 2 == 0)
                        cnt[idx] = cnt[idx-1] - 2;
                    else
                        cnt[idx] = cnt[idx-1] + 2;
                }
                times[i]++;
            }
        }
    }

    public static int dfs(int cur) {
        if (cur == n)
            return 0;
        if (cur == n-1)
            return -1;
        int maxValue = Integer.MIN_VALUE;
        for (int i=2; i<=n-cur; ++i) {
            int tempValue = cnt[getIndex(cur, cur+i-1)] + dfs(cur+i);
            maxValue = Math.max(maxValue, tempValue);
        }
        return maxValue;
    }
}
